local border_radius = require 'border_radius'
local colors = require 'color'
local division = require 'division'
local vec2 = require 'vec2'
local view = require 'views.view'
local size = require 'constrained_size'

---@class decorated_box: view
---@field color vec4,
---@field border_radius border_radius,
local decorated_box = view:new_view_type()

---@class decorated_box.renderer: view.renderer
---@field id number entity_id
decorated_box.renderer = view.renderer:new_renderer_type()

---@param self decorated_box
---@param box_options { color: vec4, border_radius: border_radius }
---@return decorated_box
function decorated_box:__call(box_options)
    self:set_view_prototype(box_options)
    box_options.color = box_options.color or colors.WHITE
    box_options.border_radius = box_options.border_radius or border_radius.all(0)

    return box_options
end

function decorated_box:create_renderer_instance()
    return self:set_renderer_prototype({ id = division:create_drawable_rect() })
end

function decorated_box.renderer:layout(constraints, view)
    return size.unconstrained()
end

---@param render_rect rect
---@param view decorated_box
function decorated_box.renderer:render(render_rect, view)
    division:set_drawable_rect(self.id, render_rect, view.color, view.border_radius)
end

function decorated_box.renderer:destroy()
    division:destroy_entity(self.id)
end

return decorated_box
